﻿using System;
using System.Text;

namespace Cfg.Exceptions
{
    public class ConfigValidationException : Exception
    {
        public ValidationError[] ValidationErrors { get; private set; }
        public Type ConfigType { get; private set; }

        public ConfigValidationException(Type t, ValidationError[] errors)
        {
            ConfigType = t;
            ValidationErrors = errors;
        }

        public override string Message
        {
            get
            {
                var message = new StringBuilder();

                message
                    .AppendFormat("Configuration '{0}' validation failed!", ConfigType)
                    .AppendLine();

                foreach (var error in ValidationErrors)
                {
                    message
                        .AppendFormat("{0}: {1}", error.Key, error.Error)
                        .AppendLine();
                }

                return message.ToString();
            }
        }
    }

    public class ConfigValidationException<T> : ConfigValidationException
    {
        public ConfigValidationException(ValidationError[] errors) : base(typeof(T), errors)
        {

        }
    }
}
